{include file="public/head"}
<link rel="stylesheet" href="__module__/flag-icon-css/css/flag-icon.css">
<style>
    .x-body {
        min-width: 1400px;
    }

    body {
        overflow-x: scroll;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">

        <div class="layui-input-inline">
            <input id="order_no" name="order_no" class="layui-input" placeholder="订单编号" value="{$Think.get.order_no}">
        </div>

        <div class="layui-input-inline layui-form">
            <select name="order_status" id="order_status">
                <option value="">订单状态</option>
                {foreach name="order_status" item="vo" key="key" }
                {if $Think.get.order_status == $key}
                <option value="{$key}" selected>{$vo}</option>
                {else/}
                <option value="{$key}">{$vo}</option>
                {/if}
                {/foreach}
            </select>
        </div>

        <div class="layui-input-inline layui-form">
            <select name="shop_id" id="shop_id">
                <option value="">选择店铺</option>
                {volist name="store" id="vo"}
                <option value="{$vo.id}" {if $Think.get.shop_id== $vo['id']} selected {/if}>{$vo.name}</option>
                {/volist}
            </select>
        </div>

        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="start" name="start" value="{$Think.get.start}"
                   placeholder="开始日期">
        </div>

        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="end" name="end" value="{$Think.get.end}" placeholder="结束日期">
        </div>

        <div class="layui-input-inline layui-form" style="width: 130px">
            <select name="unit" id="unit">
                <option value="">选择统计货币</option>
                {volist name="unit" id="vo"}
                <option value="{$vo.sign}" {if $Think.get.unit== $vo['sign']} selected {/if}>{$vo.name}</option>
                {/volist}
            </select>
        </div>

        <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
        <button class="layui-btn layui-btn-sm" onclick="search()"><i class="layui-icon layui-icon-search"></i>搜索
        </button>
        {if empty($Think.get.company_id)}
        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="getOrder()">拉取订单</button>

        <button class="layui-btn layui-btn-sm" style="background-color:#FF5722;" onclick="deliver(1)">假发货</button>
        <button class="layui-btn layui-btn-sm" style="background-color:#5FB878;" onclick="deliver(2)">真发货</button>
        {/if}
        <span class="x-right">共有数据:<i class="i_count">{$orders->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>

    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 20px;text-align:center">
                <div class="header layui-form-checkbox" lay-skin="primary" style="padding: 0 0"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align:center">系统编号</th>
            <th style="width: 80px;text-align:center">国家</th>
            <th style="width: 100px;text-align:center">商品图</th>
            <th style="min-width: 150px">亚马逊订单编号</th>
            <th style="width: 110px;text-align:center">实付价格</th>
            <th style="width: 130px;text-align:center">购买商品数量</th>
            <th style="width: 60px;text-align:center">状态</th>
            <th style="width: 130px;text-align:center">订单时间</th>
            <th style="width: 130px;text-align:center">假发货</th>
            <th style="width: 130px;text-align:center">真发货</th>
            <th style="width: 75px;text-align:center">操作</th>
        </thead>
        <tbody>

        {volist name="orders" id="vo"}
        <tr>
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}' style="padding: 0 0">
                    <i class="layui-icon">&#xe605;</i></div>
            </td>
            <td style="text-align:center">{$vo.id}</td>
            <td style="text-align:center">
                <span class="label label-default">
                    <span class="flag-icon flag-icon-{php}echo strtolower($store[$vo['shop_id']]['nation_short']){/php}"></span>
                    {$store[$vo['shop_id']]['nation']}
                </span>
            </td>
            <td style="max-height: 100px;text-align:center">
                {if isset($product[$vo['id']]['url'])}
                <img src="{$product[$vo['id']]['url']}" onclick="previewImg(this)">
                {else/}
                <img src="__images__/noimg.png">
                {/if}
            </td>
            <td>{$vo.order_no}</td>
            <td style="text-align:center">{$vo.pay_money}{$vo.coin}</td>
            <td style="text-align:center">{$vo.goods_num}</td>
            <td style="text-align:center">{$order_status[$vo.order_status]|default=''}</td>
            <td style="text-align:center">{$vo['create_time']|date="Y-m-d H:i",###}</td>
            <td style="text-align:center">
                {if $vo['fake_good_time']>0}<span style="color:#FF5722;">{$vo['fake_good_time']|date="Y-m-d H:i",###}{/if}</span>
            </td>
            <td style="text-align:center">
                {if $vo['true_good_time']>0}<span style="color:#5FB878;">{$vo['true_good_time']|date="Y-m-d H:i",###}{/if}</span>
            </td>
            <td style="text-align:center">
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('订单详情','amazonInfo.html?id={$vo.id}&company_id={$Think.get.company_id}')">详情
                </button>
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$orders->render()}
        </div>
    </div>
    <div>
        盈利({$Think.get.unit|default='CNY'})：<span style="color: #5FB878">总价：{$total}</span> -
        <span style="color: #01AAED">运费：{$shipping_money}</span> -
        <span style="color: #01AAED">成本：{$goods_money}</span> -
        <span style="color: #01AAED">手续费：{$expend_fee}</span> =
        <span style="color: #FF5722">{$profit}{$Think.get.unit|default='CNY'}</span>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var order_no = $("#order_no").val();
        var order_status = $("#order_status").val();
        var unit = $("#unit").val();
        var start = $("#start").val();
        var end = $("#end").val();
        var shop_id = $("#shop_id").val();
        var company_id = $("#company_id").val();
        location.href = "amazon.html?order_no=" + order_no + "&order_status=" + order_status + "&start=" + start + "&end=" + end + "&shop_id=" + shop_id + "&company_id=" + company_id+ "&unit=" + unit;
    }

    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function getOrder() {
        var start = $("#start").val();
        var end = $("#end").val();
        var shop_id = $("#shop_id").val();
        if (shop_id == '') {
            layer.msg("请选择拉取订单的店铺");
            return false;
        }
        if (start == '') {
            layer.msg("请选择拉取订单的开始时间");
            return false;
        }
        // 提交成功后样式修改
        layer.load(1);
        $.ajax({
            url: "{:url('admin/getamazonorders/amazon')}",
            async: true,
            dataType: 'json',
            data: {start: start, end: end, shop_id: shop_id},
            type: "post",
            success: function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        location.reload();
                    });
                }
            }
        })
    }

    function deliver(type) {
        var title = type == 1 ? '假发货' : '真发货';
        var shop_id = $("#shop_id").val();
        if (shop_id == '') {
            layer.msg("请选" + title + "订单的店铺");
            return false;
        }
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要" + title + "的订单");
            return false;
        }
        layer.confirm('确认要' + title + '？', function (index) {
            $.post("{:url('admin/amazonorder/deliver')}", {
                id: data,
                type: type,
                shop_id: shop_id
            }, function (data, textStatus, xhr) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
